package com.chinacoal.hr.levelboot.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author: YunTao.Li
 * @create: 2019-11-14 17:31
 * @description:
 **/
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {


    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("xlsCode", "HR_LEAVE", metaObject);
        this.setFieldValByName("docTypeId", "e1c4b2f3-87e5-11e7-b512-7a07f6fc3890", metaObject);
        this.setFieldValByName("explainCode", this.getRandomCode("KE"), metaObject);
        this.setFieldValByName("bizTravelCode", this.getRandomCode("BT"), metaObject);
        this.setFieldValByName("leaveCode", this.getRandomCode("LV"), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
    }

    private String getRandomCode(String header){
        int hashCodev = UUID.randomUUID().toString().hashCode();
        if(hashCodev < 0) {
            hashCodev = -hashCodev;
        }
        return header + String.format("%015d",hashCodev);
    }

}
